﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Forms;

using Gsn.Credentials.Engine;
using Gsn.Calendar.Engine;
using Gsn.Calendar.Controller;
using Gsn.UI;

namespace Gsn
{
    class Program : ApplicationContext
    {
        private CalendarEngine calendarEngine_;
        private CredentialsEngine credentialsEngine_;
        private CalendarController calendarController_;
        private TrayIconUI trayIconUI_;
        //private ConsoleUI consoleUI_;

        public Program()
        {
            // handle the ApplicationExit event to know when the application is exiting...
            Application.ApplicationExit += new EventHandler(this.OnApplicationExit);

            ///create calendar engine...
            calendarEngine_ = new CalendarEngine();

            ///create credentials engine...
            credentialsEngine_ = new CredentialsEngine();

            ///create controller...
            calendarController_ = new CalendarController(calendarEngine_, credentialsEngine_);

            ///create TrayIconUI...
            trayIconUI_ = new TrayIconUI(calendarController_);
            trayIconUI_.Visible = true;

            ///create ConsoleUI...
            //consoleUI_ = new ConsoleUI(calendarController_);
            //consoleUI_.Visible = true;

            ///start program...
            calendarController_.StartEngine();
        }

        private void OnApplicationExit(Object source, EventArgs args)
        {
            trayIconUI_.Visible = false;
            trayIconUI_ = null;

            //consoleUI_.Visible = false;
            //consoleUI_ = null;

            calendarController_.StopEngine();
            calendarController_ = null;
        }

        static void Main(string[] args)
        {
            Application.Run(new Program());
        }
    }
}
